/**   
 * @Title: GetBeidanExpectCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.beijingdanchang 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-12-8 下午12:14:26  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.beijingdanchang;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.beijingdanchang.BeidanInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.log.EDebug;

/**
 * @ClassName: GetBeidanExpectCommunicater
 * @Description: 获取北单期号
 * @author: City Jiangsy@500wan.com
 * @date: 2011-12-8 下午12:14:26
 * 
 */
public class GetBeidanExpectCommunicater extends ServerCommunicater {

	public boolean getExpect() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

		list.add(mapItem(Config.PASER_MID, BussinessCode.MID_FUCAI3D_TIMELEFT));
		list.add(mapItem(Key.KEY_LOTID, Config.BEIJINGZUQIUDANCHANG));

		super.getServerResponse(list, true);

		if (super.getState() == 100) {
			EDebug.o(this, "state is 100 走你");
			updateBeidanInfo();
			return true;
		} else {
			return false;
		}
	}

	public void updateBeidanInfo() {
		EDebug.o(this, "update 走你");

		BeidanInfo.getBeidanInfo().setExpect(super.getListResult().get(0).get(Key.KEY_EXPECT));
		EDebug.o(this, "update 走你1");
		BeidanInfo.getBeidanInfo().setLeftTime(super.getListResult().get(0).get(Key.KEY_LEFTTIME));
		EDebug.o(this, "update 完成");
	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
